package drds.configuration.web.common;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author caozhenghui@drds.team<330937205@qq.com>
 */
public class GoogleChromeFilter implements Filter {

    public void init(FilterConfig filterConfig) throws ServletException {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String userAgent = request.getHeader("User-Agent");
        if (userAgent != null && userAgent.contains("Chrome")) {
            filterChain.doFilter(servletRequest, servletResponse);
        } else {
            response.sendRedirect("http://www.baidu.com");
        }
    }

    public void destroy() {
    }

}
